package com.anycl.design.behavioral.state.instance;

/**
 * 遥控器，扮演上下文角色，负责电视机状态切换
 */
public class RemoteControlMachine {
    public final static TVState STANDBY_STATE = new StandByState();
    public final static TVState POWER_OFF_STATE = new PowerOffState();
    public final static TVState PLAY_STATE = new PlayState();

    // 当前状态
    private TVState currentState;

    public RemoteControlMachine(TVState currentState) {
        this.currentState = currentState;
        this.currentState.setRemoteControlMachine(this);
        STANDBY_STATE.setRemoteControlMachine(this);
        POWER_OFF_STATE.setRemoteControlMachine(this);
        PLAY_STATE.setRemoteControlMachine(this);
    }
    public TVState getCurrentState() {
        return currentState;
    }

    public void setCurrentState(TVState currentState) {
        this.currentState = currentState;
    }

    // 委托给state统一去处理
    public void powerOn() {
        this.currentState.powerOn();
    }

    public void powerOff() {
        this.currentState.powerOff();
    }

    public void play() {
        this.currentState.play();
    }

    public void standBy() {
        this.currentState.standby();
    }
}
